package com.example.xjtuse_pc.soapdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;

public class MainActivity extends AppCompatActivity {
public static Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       button= (Button)findViewById(R.id.we);



    }
    public void  getwe(View v){
     new Thread(){

    @Override
    public void run() {
        String url="http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl";
        String ns="http://WebXml.com.cn";
        String action="getRegionProvince";
        HttpTransportSE trans=new HttpTransportSE(url);
        SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
        SoapObject body=new SoapObject(ns, action);
        //body.addProperty("mobileCode","18868890049");
        //body.addProperty("userID","");
        envelope.setOutputSoapObject(body);
        envelope.dotNet=true;
        SoapObject so= null;
        try {
            trans.call(ns+"/"+action, envelope);
            System.out.println(envelope.bodyIn.getClass().getName());
            System.out.println(envelope.getResponse().getClass().getName());
            so = (SoapObject)envelope.getResponse();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        }


        for(int i=0;i<so.getPropertyCount();i++){
            System.out.println(so.getProperty(i));
        }
    }
}.start();


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
